function render (trackList){
    var tbody = document.querySelector('tbody')
    for(var i in trackList){
            var track = trackList[i]
            var html = `<tr><td>${track.tid}</td><td>${track.title} </td><td> ${track.refCount} </tr>`
            //添加html到内部
            tbody.innerHTML += html
    }
}
function renderPagination(pagination){
    var currentPage = parseInt(pagination.currentPage)
    if (currentPage === 1) {
           // 说明没有上一页
           document.querySelector('.prevPage').href += currentPage
       } else {
           document.querySelector('.prevPage').href += (currentPage - 1)
       }
    document.querySelector('.countPerPage').textContent = pagination.countPerPage
    document.querySelector('.currentPage').textContent = pagination.currentPage
    document.querySelector('.totalPage').textContent = pagination.totalPage
    if (currentPage === parseInt(pagination.totalPage)) {
           document.querySelector('.nextPage').href += currentPage
       } else {
           document.querySelector('.nextPage').href += (currentPage + 1)
       }
    document.querySelector('.lastPage').href += pagination.totalPage

}
function renderNoLogin(){
    document.querySelector('.who').textContent = '必须登录后才能使用'
}
function renderWho(user){
    document.querySelector('.who').textContent = user.username
}
window.onload = function(){
    var xhr = new XMLHttpRequest();
    xhr.open('get','/studio/track/list.json' + location.search)
    xhr.onload = function(){
    console.log(this.responseText)
    var data = JSON.parse(this.responseText)
    if(!data.currentUser){
        renderNoLogin()
        return
    }
    renderWho(data.currentUser)
    renderPagination(data.pagination)
    render(data.trackList)


    }
    xhr.send()

}